/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package facade;

import local.BufferFacadeLocal;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import model.Buffer;

/**
 *
 * @author Randy
 */
@Stateless
public class BufferFacade implements BufferFacadeLocal {
    @PersistenceContext(unitName = "IEMPPU")
    private EntityManager em;

    @Override
    public boolean getBuffers() {
        Query query = em.createQuery("SELECT b FROM Buffer b");

        if (query.getResultList().isEmpty()) {
            return true;
        } else {
            return false;
        }
    }
    
    @Override
    public void createBuffer() {
        for (int i=0; i<200; i++) {
            Buffer b = new Buffer();
            em.persist(b);
        }
    }
    
}
